package q1.project.modules.system.role.entity;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import q1.project.core.jpa.annotation.Comment;

/**
 * 角色菜单关联实体
 *
 * @author Q1 Team
 * @version 1.0
 */
@Getter
@Setter
@Entity
@Table(
    name = "q1_role_menu",
    indexes = {
      @Index(name = "idx_role_id", columnList = "role_id"),
      @Index(name = "idx_menu_id", columnList = "menu_id")
    })
public class RoleMenuEntity {

  /** 主键ID */
  @Comment("主键ID")
  @Id
  @Column(name = "id", length = 32)
  private String id;

  /** 角色ID */
  @Comment("角色ID")
  @Column(name = "role_id", nullable = false, length = 32)
  private String roleId;

  /** 菜单ID */
  @Comment("菜单ID")
  @Column(name = "menu_id", nullable = false, length = 32)
  private String menuId;

  /** 创建时间 */
  @Comment("创建时间")
  @Column(name = "create_time", nullable = false, updatable = false)
  private LocalDateTime createTime;

  /** 租户ID(多租户隔离) */
  @Comment("租户ID")
  @Column(name = "tenant_id", length = 32)
  private String tenantId;

  @PrePersist
  public void prePersist() {
    if (id == null) {
      id = java.util.UUID.randomUUID().toString().replace("-", "");
    }
    if (createTime == null) {
      createTime = LocalDateTime.now();
    }
  }
}
